#ifndef WSCLIENT_DEF
#define WSCLIENT_DEF

#include <winsock.h>
#include <list>
#pragma comment (lib, "Ws2_32.lib")

class WSClient
{
    friend class WSServer;
public:
    class IDataReceiver
    {		
    public:
		BOOL bDeleted; //TODO
		IDataReceiver() : bDeleted(FALSE){};
		virtual ~IDataReceiver() {bDeleted = TRUE;};
        virtual void OnData(WSClient *sender, LPVOID data, int len) = 0;
        virtual void OnConnected(WSClient *sender) = 0;
        virtual void OnConnectionClosed(WSClient *sender) = 0;
    };    
private:
    volatile SOCKET m_Socket;
    volatile BOOL m_bConnected;
    LPSTR m_Ip;
    int m_Port;
	std::list<IDataReceiver*> m_EventOnData;
    HANDLE hThread;

    static void ThreadFunc(LPVOID p);
    typedef struct Data
    {
        WSClient* client;
        char* p;
        int len;
    }Data;
    static void ThreadToSendData(LPVOID p);
    WSClient(SOCKET handle);   

    void NativeSend( void* msg, int len );
protected:
    virtual void OnData(LPVOID data, int len);
    virtual void OnConnectionClosed();
    virtual void OnConnected();
public:	
    WSClient(LPSTR ip, int port);
    virtual ~WSClient();
    void Send(char *msg);
    void Send( void* msg, int len );
    void SetDataReceiver(IDataReceiver *obj);
};
#endif